import Vue from "vue";
import VueRouter from "vue-router";
import HomeView from "../views/HomeView.vue";

Vue.use(VueRouter);

const routes = [
  {
    path: '/sharelife',
    name: 'sharelife',
    component: () => import('../views/ShareLife.vue'),
  },
  {
    path: '/upload1',
    name: 'upload1',
    component: () => import('../views/UpLoad1.vue'),
  },
  {
    path: '/content',
    name: 'content',
    component: () => import('../views/ContentView.vue'),
  },
  {
    path: "/",
    name: "首页",
    component: HomeView,
  },
  {
    path: "/article/:id",
    name: "详情页",
    component: () => import("../views/AboutView.vue"),
  },
  {
    path: "/register",
    name: "注册",
    component: () => import("../views/RegisterView.vue"),
  },
  {
    path: "/login",
    name: "登录",
    component: () => import("../views/LoginPage.vue"),
  },
  {
    path: "/myself",
    name: "个人信息",
    component: () => import("../views/MySelf.vue"),
  },
  {
    path: "/circle",
    name: "烘培圈",
    component: () => import("../views/CircleView.vue"),
  },
  {
    path: "/category",
    name: "分类",
    component: () => import("../views/CateGory.vue"),
  },
  {
    path: "/select",
    name: "搜索",
    component: () => import("../views/MySelect.vue"),
    // component: select,
    children: [
      {
        path: "recipe",
        name: "搜索结果",
        component: () => import("../views/select/RecipeView.vue"),
      },
    ],
  },
];

// 解决重复跳转的方法
// 在VUE中路由遇到Error: Avoided redundant navigation to current location:报错显示是路由重复
//获取原型对象上的push函数
const originalPush = VueRouter.prototype.push;
//修改原型对象中的push方法
VueRouter.prototype.push = function push(location) {
  return originalPush.call(this, location).catch(err => err);
};

const router = new VueRouter({
  mode: "history",
  base: process.env.BASE_URL,
  routes,
});

export default router;
